@use '../config';
@use './util';

/* - Typography 字体排版 -
************************* */

// Font Family
@if util.expect(config.$abbr-font-family) {

  #{util.class-generator(config.$abbr-font-family, sans)}
  {
    font-family: ui-sans-serif,
      system-ui,
      -apple-system,
      BlinkMacSystemFont,
      "Segoe UI",
      Roboto,
      "Helvetica Neue",
      Arial,
      "Noto Sans",
      sans-serif,
      "Apple Color Emoji",
      "Segoe UI Emoji",
      "Segoe UI Symbol",
      "Noto Color Emoji";
  }

  #{util.class-generator(config.$abbr-font-family, serif)}
  {
    font-family: ui-serif,
      Georgia,
      Cambria,
      "Times New Roman",
      Times,
      serif;
  }

  #{util.class-generator(config.$abbr-font-family, mono)}
  {
    font-family: ui-monospace,
      SFMono-Regular,
      Menlo,
      Monaco,
      Consolas,
      "Liberation Mono",
      "Courier New",
      monospace;
  }

}


// Font Size
@if util.expect(config.$abbr-font-size) {

  @each $key, $value in util.map-handler(config.$map-fontSize) {

    #{util.class-generator(config.$abbr-font-size, $key)}
    {
      font-size: $value;
      line-height: map-get($map: util.map-handler(config.$map-fontSizeLineHeight), $key: $key);
    }

  }

}

// Font Smoothing
@if util.expect(config.$abbr-font-smoothing) {

  #{util.class-generator(config.$abbr-font-smoothing)}
  {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  #{util.class-generator(subpixel, config.$abbr-font-smoothing)}
  {
    -webkit-font-smoothing: auto;
    -moz-osx-font-smoothing: auto;
  }

}

// Font Style
@if util.expect(config.$abbr-font-style) {

  #{util.class-generator(config.$abbr-font-style)}
  {
    font-style: italic;
  }

  #{util.class-generator('not', config.$abbr-font-style)}
  {
    font-style: normal;
  }

}

// Font Weight
@if util.expect(config.$abbr-font-weight) {

  @each $key, $value in util.map-handler(config.$map-fontWeight) {

    #{util.class-generator(config.$abbr-font-weight, $key)}
    {
      font-weight: $value;
    }

  }

}

// Letter Spacing
@if util.expect(config.$abbr-letter-spacing) {

  @each $key, $value in util.map-handler(config.$map-letterSpacing) {

    #{util.class-generator(config.$abbr-letter-spacing, $key)}
    {
      letter-spacing: $value;
    }

  }

}

// Line Height
@if util.expect(config.$abbr-line-height) {

  @each $key, $value in util.map-handler(config.$map-lineHeight) {

    #{util.class-generator(config.$abbr-line-height, $key)}
    {
      line-height: $value;
    }

  }

}

// List Style Type
@if util.expect(config.$abbr-list-style) {

  @each $key, $value in util.map-handler(config.$map-listStyleType) {

    #{util.class-generator(config.$abbr-list-style, $key)}
    {
      list-style-type: $value;
    }

  }

}

// Text Align
@if util.expect(config.$abbr-text-align) {

  @each $value in (
    left,
    center,
    right,
    justify
  ) {

    #{util.class-generator(config.$abbr-text-align, $value)}
    {
      text-align: $value;
    }

  }

}

// Text Color
@if util.expect(config.$abbr-text-color) {

  @each $outer-key, $outer-value in util.map-handler(config.$map-textColor) {

    // transparent 为内置关键字，加 ’‘ 转换为普通字符串
    @if ($outer-key == inherit) or ($outer-key == 'current') or ($outer-key == transparent + '') or ($outer-key == 'black') or ($outer-key == 'white') {

      #{util.class-generator(config.$abbr-text-color, $outer-key)}
      {
        color: $outer-value;
      }

    }
    @else {

      #{util.class-generator(config.$abbr-text-color, $outer-key)}
      {
        --text-opacity: 1;
        color: rgba($color: $outer-value, $alpha: var(--text-opacity, 1));
      }

      @each $inner-key, $inner-value in util.map-handler(util.$map-color-brightness) {

        #{util.class-generator(config.$abbr-text-color, $outer-key, $inner-key)}
        {
          --text-opacity: 1;
          color: rgba($color: util.lighter-color($outer-value, $inner-value), $alpha: var(--text-opacity, 1));
        }

      }

    }

  }

}


// Text Color Opacity
@if util.expect(config.$abbr-text-opacity) {

  @each $key, $value in util.map-handler(config.$map-textOpacity) {

    #{util.class-generator(config.$abbr-text-opacity, $key)}
    {
      --text-opacity: #{$value};
    }

  }

}

// Text Decoration
@if util.expect(config.$abbr-text-decoration) {

  @each $key, $value in (
    underline: underline,
    line-through: line-through,
    no-underline: none
  ) {

    #{util.class-generator(config.$abbr-text-decoration, $key)}
    {
      text-decoration: $value;
    }

  }

}

// Text Transform
@if util.expect(config.$abbr-text-transform) {

  @each $key, $value in (
    uppercase: uppercase,
    lowercase: lowercase,
    capitalize: capitalize,
    normal-case: none
  ) {

    #{util.class-generator(config.$abbr-text-transform, $key)}
    {
      text-transform: $value;
    }

  }

}

// Text Overflow
@if util.expect(config.$abbr-text-overflow) {

  #{util.class-generator(truncate)}
  {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #{util.class-generator(config.$abbr-text-overflow, ellipsis)}
  {
    text-overflow: ellipsis;
  }

  #{util.class-generator(config.$abbr-text-overflow, clip)}
  {
    text-overflow: clip;
  }

}

// Line clamp
@if util.expect(config.$abbr-line-clamp) {

  #{util.class-generator(config.$abbr-line-clamp, 1)} {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  %clamp-base {
    word-break: break-all;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  $line-clamp-index: 2;

  @while $line-clamp-index <=6 {

    #{util.class-generator(config.$abbr-line-clamp, $line-clamp-index)} {
      @extend %clamp-base;
      -webkit-line-clamp: $line-clamp-index;
    }

    $line-clamp-index: util.big($line-clamp-index);

  }

}

// Vertical Align
@if util.expect(config.$abbr-vertical-align) {

  @each $value in (
    baseline,
    top,
    middle,
    bottom,
    text-top,
    text-bottom
  ) {

    #{util.class-generator(config.$abbr-vertical-align, $value)}
    {
      vertical-align: $value;
    }

  }

}

// White Space
@if util.expect(config.$abbr-white-space) {

  @each $value in (
    normal,
    nowrap,
    pre,
    pre-line,
    pre-wrap
  ) {

    #{util.class-generator(config.$abbr-white-space, $value)}
    {
      white-space: $value;
    }

  }

}

// Word Break
@if util.expect(config.$abbr-word-break) {

  #{util.class-generator(config.$abbr-word-break, normal)}
  {
    overflow-wrap: normal;
    word-break: normal;
  }

  #{util.class-generator(config.$abbr-word-break, words)}
  {
    overflow-wrap: break-word;
  }

  #{util.class-generator(config.$abbr-word-break, all)}
  {
    word-break: break-all;
  }

}

// Text Indent
@if util.expect(config.$abbr-text-indent) {

  @each $key, $value in util.map-handler(config.$map-textIndent) {

    #{util.class-generator(config.$abbr-text-indent, $key)}
    {
      text-indent: $value;
    }

  }

}
